package conf

import "fmt"

func NewDefaultConfig() *Config {
	return &Config{
		Auth: NewDefaultAuth(),
	}
}

//程序配置对象
// toml 映射
// env 映射
type Config struct {
	Auth *Auth `toml:"auth"`
}

func NewDefaultAuth() *Auth {
	return &Auth{
		Username: "admin",
		Password: "123456",
	}
}

// auth配置,需要通过toml格式来进行读取,也需要通过环境来进行读取
type Auth struct {
	Username string `toml:"username" env:"AUTH_USERNAME"`
	Password string `toml:"password" env:"AUTH_PASSWORD"`
}

func (a *Auth) Validate(username, password string) error {
	if !(a.Username == username && a.Password == password) {
		return fmt.Errorf("用户密码或者密码不对")
	}

	return nil
}
